﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using OnlineMealOrdering.Common;
using OnlineMealOrdering.Domain;
using OnlineMealOrdering.Extends.MvcPager;

namespace OnlineMealOrdering.Models
{
    public class StoreOnlineModel : ModelBase
    {
        public int Id { get; set; }

        [Display(Name = "店铺名称")]
        [Required(ErrorMessage = "店铺名称不能为空")]
        public string Name { get; set; }

        [Display(Name = "图片")]
        public string Image { get; set; }

        [Display(Name = "短名称")]
        [Required(ErrorMessage = "短名称不能为空")]
        public string PinYin { get; set; }

        [Display(Name = "店铺描述")]
        [Required(ErrorMessage = "店铺描述")]
        public string Description { get; set; }

        [Display(Name = "电话")]
        [Required(ErrorMessage = "电话不能为空")]
        [RegularExpression(@"(^(\d{3,4}-)?\d{7,8})$|(13[0-9]{9})", ErrorMessage = "手机号码格式不正确(如:0755-11223344)")]
        public string Tel { get; set; }

        [Display(Name = "手机号码")]
        [Required(ErrorMessage = "手机号码不能为空")]
        [RegularExpression(@"(^(\d{3,4}-)?\d{7,8})$|(13[0-9]{9})", ErrorMessage = "手机号码格式不正确(如:13510426755)")]
        public string Phone { get; set; }

        [Display(Name = "QQ号码")]
        public string QQ { get; set; }

        [Display(Name = "微博号码")]
        public string WeiBo { get; set; }

        [Display(Name = "店铺详细内容介绍")]
        public string Contact { get; set; }

        [Display(Name = "营业开始时间")]
        public DateTime BeginBusinessTime { get; set; }

        [Display(Name = "营业结束时间")]
        public DateTime EndBusinessTime { get; set; }

        public List<MarkModel> Marks { get; set; }

        public List<FoodCatalogModel> Catalogs { get; set; }

        //经度
        public decimal Longitude { get; set; }
        //维度
        public decimal Latitude { get; set; }

        

        public string StrType
        {
            get
            {
                return EnumHelper.GetEnumDescription(Type);
            }
        }

        //电话订餐还是网上订单
        public EnunStoreType Type { get; set; }

        //起步价
        [Display(Name = "起步价格")]
        [Required(ErrorMessage = "起步价格不能为空")]
        public decimal InitiatePrice { get; set; }

        public string Address { get; set; }

        public EnumStoreStatus Status { get; set; }

        public string StrStatus
        {
            get
            {
                return EnumHelper.GetEnumDescription(Status);
            }
        }

        public int SortNo { get; set; }

        public string Note { get; set; }




        #region Public Method

        public static StoreOnlineModel GetStoreOnline(int id)
        {
            var entity = Ctx.EntitySet<StoreOnlineEntity>().SingleOrDefault(a => a.Id == id);
            return entity.ToStoreOnlineModel();
        }

        public static PagedList<StoreOnlineModel> GetAllStoreOnline(int pagindex = 1, int pagsize = 10)
        {
            var query = Ctx.EntitySet<StoreOnlineEntity>().OrderBy(a => a.SortNo);
            var model = query.ToPagedList(a => a.ToStoreOnlineModel(), pagindex, pagsize);
            return model;
        }




        #endregion



    }
}